package {{package}};

import io.datahubproject.openapi.delegates.EntityApiDelegateImpl;
import com.linkedin.metadata.entity.EntityService;
import com.linkedin.metadata.search.SearchService;
import io.datahubproject.openapi.entities.EntitiesController;
import com.datahub.authorization.AuthorizerChain;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Value;

{{#imports}}import {{import}};
{{/imports}}

{{^isDelegate}}
import com.fasterxml.jackson.databind.ObjectMapper;
{{/isDelegate}}

{{#useOas2}}
import io.swagger.annotations.*;
{{/useOas2}}
{{^useOas2}}
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
{{/useOas2}}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
{{^useOas2}}
{{/useOas2}}
import org.springframework.web.multipart.MultipartFile;

    {{#useBeanValidation}}
import javax.validation.constraints.*;
import javax.validation.Valid;
    {{/useBeanValidation}}

{{^isDelegate}}
import javax.servlet.http.HttpServletRequest;
    {{#isJava8or11}}
import java.util.Optional;
    {{/isJava8or11}}
{{/isDelegate}}
{{^jdk8-no-delegate}}
    {{#useOptional}}
import java.util.Optional;
    {{/useOptional}}
{{/jdk8-no-delegate}}

    {{^isDelegate}}
import java.io.IOException;
    {{/isDelegate}}
import java.util.List;
import java.util.Map;
    {{#async}}
import java.util.concurrent.Callable;
    {{/async}}

{{>generatedAnnotation}}
{{#useOas2}}
{{/useOas2}}
{{^useOas2}}
{{/useOas2}}
{{#operations}}
@RestController
@RequestMapping("/v2/entity")
public class {{classname}}Controller implements {{classname}} {

    private static final Logger log = LoggerFactory.getLogger({{classname}}Controller.class);

    private final ObjectMapper objectMapper;

    private final HttpServletRequest request;

    private final EntityApiDelegateImpl<{{requestClass}}, {{responseClass}}, {{scrollResponseClass}}> delegate;

    @org.springframework.beans.factory.annotation.Autowired
    public {{classname}}Controller(ObjectMapper objectMapper, HttpServletRequest request, EntityService entityService,
    SearchService searchService, EntitiesController v1Controller, AuthorizerChain authorizationChain,
    @Value("${authorization.restApiAuthorization:false}") boolean restApiAuthorizationEnabled) {
        this.objectMapper = objectMapper;
        this.request = request;
        this.delegate = new EntityApiDelegateImpl<{{requestClass}}, {{responseClass}}, {{scrollResponseClass}}>(entityService, searchService, v1Controller,
        restApiAuthorizationEnabled, authorizationChain, {{requestClass}}.class, {{responseClass}}.class, {{scrollResponseClass}}.class);
    }
    {{#isJava8or11}}

    @Override
    public Optional<ObjectMapper> getObjectMapper() {
        return Optional.ofNullable(objectMapper);
    }

    @Override
    public Optional<HttpServletRequest> getRequest() {
        return Optional.ofNullable(request);
    }
    {{/isJava8or11}}

{{#operation}}
{{#contents}}
{{#@first}}
    @Override
    public ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#parameters}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{#hasMore}},{{/hasMore}}{{/parameters}}) {
        return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
    }

{{/@first}}
{{/contents}}
{{/operation}}
}
{{/operations}}